package question9;

import question6.Animal;
import question6.Cat;
import question7.Dog;

import java.util.Scanner;

/**
 * @FileName Test
 * @Description
 * @Author Sword
 * @date 2024-10-23
 **/
public class Test {
    public static void main(String[] args) {
        //在上题的基础上编程创建一个长度为4的 Animal 类的数组
        Animal[] animals = new Animal[4];

        Scanner sc = new Scanner(System.in);

        //并创建该数组中的偶数元素为 Cat 类的对象，奇数元素为 Dog 类的对象
        //调用数组中所有对象的 speak() 方法。
        for (int i = 0; i < animals.length; i++) {
            if (i % 2 == 0) {
                Cat cat = new Cat();
                System.out.println("请输入猫的名字");
                cat.setName(sc.next());
                System.out.println("请输入猫的年龄");
                cat.setAge(sc.nextInt());
                animals[i] = cat;
                cat.speak();
            } else {
                Dog dog = new Dog();
                System.out.println("请输入狗的名字");
                dog.setName(sc.next());
                System.out.println("请输入狗的年龄");
                dog.setAge(sc.nextInt());
                animals[i] = dog;
                dog.speak();
            }
        }
    }
}
